import fetch from 'isomorphic-fetch'

const BaseURL = 'http://127.0.0.1:3009'

const uid = 101;

const userURL = BaseURL + "/user/" + uid;

export const GET_USER = (data) => {
    return {
        type: 'GET_USER',
        data
    }
}

export const getUser = ()=> {
    return fetchData(userURL, GET_USER);
}

const fetchData = (url, action, cookie = {})=> {
    return function (dispatch) {
        // ... begin
        return fetch(url, cookie)
            .then(response=> response.json())
            .then(json=> {
                // ... success
                dispatch(action(json.data));
            })
            .catch(err=> {
                //...
            });
    }
}
